<cfsetting enablecfoutputonly="true">
<cfswitch expression="#thisTag.executionMode#">
	<cfcase value="start">
		<cfparam name="attributes.id" default="">
		<cfparam name="attributes.data" default="">
		<cfparam name="attributes.link" default="">
		<cfparam name="attributes.linkField" default="">
		<cfparam name="attributes.ordered" default=False>
		<cfparam name="attributes.xpathDisplayString" default="">
		<cfparam name="attributes.xpathLinkString" default="">
		<cfparam name="attributes.displayField" default="">
		<cfparam name="attributes.innerAttribs" default="#structNew()#">
		<cfparam name="attributes.innerAttribValues" default="#structNew()#">
		<cfparam name="attributes.xpathInnerAttribValues" default="#structNew()#">
		<cfparam name="attributes.delimiters" default=",">
		<cfif StructKeyExists(caller,'root')>
			<cfset root = caller.root>
		<cfelse>
			<cfset root = caller>
		</cfif>
		<cfif NOT thisTag.hasEndTag>
			<cfthrow detail="End tag required" message="All coop tags require an end tag." errorcode="sos.tag.attributes">
		</cfif>			
		<cfif attributes.id EQ ''>
			<cfthrow detail="Missing required attribute: 'id'" message="'id' attribute is required">
		</cfif>
		<cfif NOT structKeyExists(root,"coop")>
			<cfthrow detail="Missing required COOP object on calling page.">
		</cfif>
		<cfscript>
		standardattributes = 'id,data,displayField,xpathDisplayString,xpathLinkString,ordered,delimiters,link,linkField,innerAttribs,innerAttribValues';
		ignoredInnerAttributes = 'id';
		contentAttributeList = '';
		attributes = root.coop.mergeAttributes(attributes,root);
		attributeList = root.coop.createAttributeList(attributes,standardAttributes,root);
		contentAttributeList = root.coop.createAttributeList(attributes.innerAttribs,contentAttributeList,root);
		listItemAttributes = '';
		contentAttributeValuesList = '';
		innerDataAttributeList = '';
		innerAttributeList = '';
		thisTag.innerAttributes = arrayNew(1);
		</cfscript>
	</cfcase>
	<cfcase value="end">
		<cfsavecontent variable="formElement">
			<cfscript>
			thisTag.innerDataAttributes = structNew();
			for (iAttrib in thisTag.innerAttributes[1]) {
				if (left(iAttrib,5) EQ 'data_') {
					thisTag.innerDataAttributes[iAttrib] = thisTag.innerAttributes[1][iAttrib];
					structDelete(thisTag.innerAttributes[1],iAttrib);
				}
			}
			</cfscript>
			<cfdump var="#thisTag.innerDataAttributes#">
			<cfscript>
			innerAttributeList = root.coop.createAttributeList(thisTag.innerAttributes[1],ignoredInnerAttributes,root);
			if (isSimpleValue(attributes.data) AND attributes.data EQ ''){
				attributes.data = thisTag.generatedContent;
				thisTag.generatedContent = '';
			}
			returnData = createObject("component","#root.coop._getClassPath()#objects.coop.returnData").init(attributes.data,attributes.delimiters);
			if (attributes.xpathDisplayString EQ '') {
				recordCount = returnData.recordCount();
			} else {
				recordCount = returnData.recordCount(xpathString:attributes.xpathDisplayString);
			}
			if (attributes.ordered) {
				writeOutput('<ol id="#attributes.id#"#attributeList#>');	
			} else {
				writeOutput('<ul id="#attributes.id#"#attributeList#>');
			}
			for(iListItem=1; iListItem LTE recordCount; iListItem = iListItem + 1) {
				if (attributes.xpathdisplayString EQ '') {
					display = returnData.getData(position:iListItem,column:attributes.displayField);
				} else {
					display = returnData.getData(position:iListItem,xpathString:attributes.xpathDisplayString);
				}
				if (listLen(structKeyList(attributes.innerAttribValues)) NEQ 0) {
					for (iAttrib in innerAttribValues) {
						contentAttributeValuesList = listAppend(contentAttributeValuesList,' #iAttrib#="#returnData.getData(position:iListItem,column:attributes.innerAttribValues[iAttrib])#"');
					}
				} else if (listLen(structKeyList(attributes.xpathInnerAttribValues)) NEQ 0) {
					for (iAttrib in xpathInnerAttribValues) {
						contentAttributeValuesList = listAppend(contentAttributeValuesList,' #iAttrib#="#returnData.getData(position:iListItem,column:attributes.xpathInnerAttribValues[iAttrib])#"');
					}
					
				}
				for (iAttrib in thisTag.innerDataAttributes) {
					if (reFindNoCase("##*##",thisTag.innerDataAttributes[iAttrib])) {
						innerDataAttributeList = listAppend(innerDataAttributeList,'#right(iAttrib,len(iAttrib)-5)#="#evaluate(thisTag.innerDataAttributes[iAttrib])#""'," ");
					}
				}
				writeOutput('<li#innerAttributeList##innerDataAttributeList#>');
				if (attributes.link NEQ '') {
					link = '';
					if (attributes.linkField NEQ '') {
						link = returnData.getData(position:iListItem,column:attributes.LinkField);
					} else if (attributes.xpathLinkString NEQ '') {
						link = returnData.getData(position:iListItem,xpathString:attributes.xpathLinkString);
					}
					writeOutput('<a href="#attributes.link##link#"#contentAttributeList##contentAttributeValueList#>#display#</a>');
				}
				else if (attributes.link EQ '' AND attributes.linkField NEQ '' OR attributes.link EQ '' AND attributes.linkField NEQ ''){
					if (attributes.linkField NEQ '') {
						link = returnData.getData(position:iListItem,column:attributes.LinkField);
					} else if (attributes.xpathLinkString NEQ '') {
						link = returnData.getData(position:iListItem,xpathString:attributes.xpathLinkString);
					}
					writeOutput('<a href="#attributes.link##link#"#contentAttributeList##contentAttributeValueList#>#display#</a>');
				} else {
					writeOutput(display);
				}
					writeOutput('</li>');
				contentAttributeValuesList = '';
			}
			if (attributes.ordered) {
				writeOutput('</ol>');
			} else {
			writeOutput('</ul>');
			}
			</cfscript></cfsavecontent>
			<cfoutput>#formElement#</cfoutput>
		</cfcase>
</cfswitch>
<cfsetting enablecfoutputonly="false">